﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T13_asyncAndawait
{
    class Program
    {
        static void Main(string[] args)
        {
            //string str = GetText();
            //Console.WriteLine(str);

            string str2 = GetTextAsync().Result;
            Console.WriteLine(str2);

            Console.WriteLine("主线程运行......");
            Console.Read();
        }

        static string GetText()
        {
            FileStream stream = new FileStream("myFile.txt", FileMode.Open);
            byte[] bs = new byte[stream.Length];
            stream.Read(bs, 0, bs.Length);

            return Encoding.UTF8.GetString(bs);
        }

        static async Task<string> GetTextAsync()
        {
            FileStream stream = new FileStream("myFile.txt", FileMode.Open);
            byte[] bs = new byte[stream.Length];
            await stream.ReadAsync(bs, 0, bs.Length);

            return Encoding.UTF8.GetString(bs);
        }
    }
}
